package com.yaodian100.ec.order.entity;

/**
 * @author jinwei.lin
 *
 */
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.OrderBy;
import javax.persistence.PrimaryKeyJoinColumn;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;
import javax.xml.bind.annotation.XmlTransient;

import org.apache.commons.lang.StringUtils;
import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;
import org.hibernate.annotations.NamedQueries;
import org.hibernate.annotations.NamedQuery;
import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;
import org.hibernate.annotations.Parameter;

import com.yaodian100.core.common.entity.BaseEntity;
import com.yaodian100.core.common.utils.DateUtil;
import com.yaodian100.ec.shopping.entity.CartOrders;

@Entity
@Table(name = "EC_ORDER_MAIN")
@NamedQueries( {
		@NamedQuery(name = "Orders.getAllOrdersMemberId", query = "select memberId from Orders where to_date(to_char(createDate,'yyyy/MM/dd'),'yyyy/MM/dd') = to_date(to_char(sysdate,'yyyy/MM/dd'),'yyyy/MM/dd') group by memberId"),
		@NamedQuery(name = "Orders.getAllOrdersMemberIdSize", query = "select count(distinct memberId) from Orders where to_date(to_char(createDate,'yyyy/MM/dd'),'yyyy/MM/dd') = to_date(to_char(sysdate,'yyyy/MM/dd'),'yyyy/MM/dd')") })
public class Orders extends BaseEntity {

	public enum ORDER_BEAN {
		CREATE("EC-OrderCreateJob"), CANCEL("EC-OrderCancelJob");
		String value;

		ORDER_BEAN(String bean) {
			this.value = bean;
		}

		public String getValue() {
			return this.value;
		}
	}

	public enum ORDER_ST {
		INIT("00"), ORDER_CREATE("10"), WAIT_FOR_DELIVER("20"), DELIVER_PROCESSING("25"), DELIVERED("30"), ARRIVED("35"), SUCCESS(
				"90"), FAILED("70"), CANCEL_BY_USER("81"), CANCEL_BY_SYSTEM("80"), CANCEL_BY_NOT_APPROVE("82"), CANNOT_DELIVER_COD(
				"60"), CANNOT_DELIVER("61"), SWITCH_TO_NEW_ORDER("83");
		String value;

		ORDER_ST(String type) {
			this.value = type;
		}

		public String getValue() {
			return this.value;
		}
	}

	public enum ORDER_PAYMENT_TYPE {
		BANK("10"), POST("20"), ARRIVE("30"), MY_WALLET("40"), ONLINE("50"), ARRIVE_CARD("60");
		String value;

		ORDER_PAYMENT_TYPE(String type) {
			this.value = type;
		}

		public String getValue() {
			return this.value;
		}
	}

	public enum ORDER_LOGISTIC_PROVIDER_TP {
		DEFAULT_PROVIDER("50"), COD_PROVIDER("51"), NOT_COD_PROVIDER("52");
		String value;

		ORDER_LOGISTIC_PROVIDER_TP(String type) {
			this.value = type;
		}

		public String getValue() {
			return this.value;
		}
	}

	/**
	 * 
	 */
	private static final long serialVersionUID = -1201865269797952189L;

	@Id
	@GeneratedValue(generator = "seq_ec_orders_main")
	@GenericGenerator(name = "seq_ec_orders_main", strategy = "com.yaodian100.core.common.dao.hibernate.OrderIdSeqGenerator", parameters = {
			@Parameter(name = "sequence", value = "seq_ec_orders_main"), @Parameter(name = "pattern", value = "000000"),
			@Parameter(name = "datePattern", value = "yyMMdd") })
	@Column(name = "order_id", length = 13)
	private String orderId;
	@Column(name = "org_order_id", length = 13)
	private String orgOrderId;
	@Column(name = "new_order_id", length = 200)
	private String newOrderId;
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "order_dt", nullable = false)
	private Date orderDt;

	// 會員資訊
	@Column(name = "member_id", length = 10, nullable = false)
	private String memberId;

	@Column(name = "login_id", length = 100, nullable = false)
	private String loginId;

	@Column(name = "member_name", length = 100, nullable = false)
	private String memberName;

	// 寄送資訊
	@Column(name = "receiver_name", length = 20)
	private String receiverName = "";

	@Column(name = "receiver_province", length = 20)
	private String receiverProvince = "";

	@Column(name = "receiver_city", length = 20)
	private String receiverCity = "";

	@Column(name = "receiver_area", length = 20)
	private String receiverArea = "";

	@Column(name = "receiver_zip", length = 10)
	private String receiverZip = "";

	@Column(name = "receiver_addr", length = 100)
	private String receiverAddr = "";

	@Column(name = "receiver_mobile", length = 20)
	private String receiverMobile = "";

	@Column(name = "receiver_phone_area", length = 10)
	private String receiverPhoneArea = "";

	@Column(name = "receiver_phone", length = 20)
	private String receiverPhone = "";

	@Column(name = "receiver_ext", length = 10)
	private String receiverExt = "";

	@Column(name = "receiver_email", length = 100)
	private String receiverEmail = "";

	@Column(name = "receiver_tp", length = 5, nullable = false)
	private String receiverTp = "10";

	// 付款資訊
	@Column(name = "payment_tp", length = 5, nullable = false)
	private String paymentTp;

	@Column(name = "payment_st", length = 5, nullable = false)
	private String paymentSt = "00";

	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "payment_dt")
	private Date paymentDt;

	@Column(name = "order_st", length = 5, nullable = false)
	private String orderSt = "00";

	// 金額資訊
	/** amount, totalPrice-coupon-discount / 同 cart.amount-coupon */
	@Column(name = "amount", columnDefinition = "numeric(10,2)")
	private BigDecimal amount = BigDecimal.ZERO;

	/** discount, 折扣金額 sum(orderProduct.discount) */
	@Column(name = "discount", columnDefinition = "numeric(10,2)")
	private BigDecimal discount = BigDecimal.ZERO;

	/** cash */
	@Column(name = "cash", columnDefinition = "numeric(10,2)")
	private BigDecimal cash = BigDecimal.ZERO;

	/** shipfare, 運費 */
	@Column(name = "shipfare", columnDefinition = "numeric(10,2)")
	private BigDecimal shipfare = BigDecimal.ZERO;

	@Column(name = "my_wallet", columnDefinition = "numeric(10,2)")
	private BigDecimal myWallet = BigDecimal.ZERO;

	/** coupon, 使用 coupon 面額 */
	@Column(name = "coupon", columnDefinition = "numeric(10,2)")
	private BigDecimal coupon = BigDecimal.ZERO;

	@Column(name = "bonus", columnDefinition = "numeric(10,2)")
	private BigDecimal bonus = BigDecimal.ZERO;

	@Column(name = "benefit", columnDefinition = "numeric(10,2)")
	private BigDecimal benefit = BigDecimal.ZERO;

	@Column(name = "return_cash", columnDefinition = "numeric(10,2)")
	private BigDecimal returnCash = BigDecimal.ZERO;

	@Column(name = "return_my_wallet", columnDefinition = "numeric(10,2)")
	private BigDecimal returnMyWallet = BigDecimal.ZERO;

	@Column(name = "return_bonus", columnDefinition = "numeric(10,2)")
	private BigDecimal returnBonus = BigDecimal.ZERO;

	@Column(name = "return_coupon", columnDefinition = "numeric(10,2)")
	private BigDecimal returnCoupon = BigDecimal.ZERO;

	@Column(name = "return_benefit", columnDefinition = "numeric(10,2)")
	private BigDecimal returnBenefit = BigDecimal.ZERO;

	@Column(name = "RETURN_SHIPFARE", columnDefinition = "numeric(10,2)")
	private BigDecimal returnShipfare = BigDecimal.ZERO;

	@Column(name = "must_pay", columnDefinition = "numeric(10,2)")
	private BigDecimal mustPay = BigDecimal.ZERO;
	/**
	 * 已退款金額
	 */
	@Column(name = "return_total_price", columnDefinition = "numeric(10,2)")
	private BigDecimal returnTotalPrice = BigDecimal.ZERO;

	@Column(name = "channel", length = 100, nullable = false)
	private String channel;

	@Column(name = "channel_seq", nullable = false)
	private int channelSeq;

	@Column(name = "b2e_id", length = 20)
	private String b2eId;

	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "deadline", nullable = false)
	private Date deadline;

	// 發票資訊, 預設 01
	@Column(name = "invoice_tp", length = 5, nullable = false)
	private String invoiceTp = "01";

	@Column(name = "invoice_title", length = 50)
	private String invoiceTitle = " ";

	@Column(name = "invoice_province", length = 20)
	private String invoiceProvince = " ";

	@Column(name = "invoice_city", length = 20)
	private String invoiceCity = " ";

	@Column(name = "invoice_area", length = 20)
	private String invoiceArea = " ";

	@Column(name = "invoice_zip", length = 10)
	private String invoiceZip = " ";

	@Column(name = "invoice_addr", length = 100)
	private String invoiceAddr = " ";

	@Column(name = "invoice_number", length = 30)
	private String invoiceNumber = " ";

	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "invoice_dt")
	private Date invoiceDt;

	@Column(name = "memo", length = 300)
	private String memo;

	@Column(name = "client_ip", length = 100, nullable = false)
	private String clientIp;

	@Column(name = "is_campaign")
	private boolean isCampaign = false;

	// 倉儲運送發起資訊
	@Column(name = "from_province", length = 20)
	private String fromProvince = " ";

	@Column(name = "from_city", length = 20)
	private String fromCity = " ";

	@Column(name = "from_district", length = 20)
	private String fromDistrict = " ";

	@Column(name = "is_sync")
	private boolean isSync = false;

	@Column(name = "payment_id", length = 20)
	private String paymentId;

	@OneToMany(mappedBy = "order")
	@LazyCollection(LazyCollectionOption.FALSE)
	@OrderBy("prodSeq asc")
	@Cascade( { CascadeType.SAVE_UPDATE, CascadeType.DELETE_ORPHAN })
	private List<OrderProduct> orderProduct;
	@OneToMany(mappedBy = "order")
	@LazyCollection(LazyCollectionOption.FALSE)
	@Cascade( { CascadeType.SAVE_UPDATE, CascadeType.DELETE_ORPHAN })
	private List<ApplyCampaign> applyCampaigns;
	@Column(name = "total_price", columnDefinition = "numeric(10,2)")
	private BigDecimal totalPrice = BigDecimal.ZERO;

	// 支付的厂商
	@Column(name = "payment_src", length = 20)
	private String paymentSrc = " ";
	@Column(name = "sync_date")
	private Date syncDt;

	@Column(name = "camp_product_limit", columnDefinition = "numeric(10,2)")
	private BigDecimal campProductLimit = BigDecimal.ZERO;
	@Transient
	private int productSum = 0;

	/**
	 * channel要回傳的參數
	 */
	@Column(name = "CHANNEL_CHILD", length = 500)
	private String channel_child;

	@Column(name = "DOMAIN_SRC", length = 30)
	private String domainSrc;

	/**
	 * 记录该订单之商品总重量
	 */
	@Column(name = "TOTAL_WEIGHT", columnDefinition = "NUMERIC(10, 2)")
	private BigDecimal totalWeight = BigDecimal.ZERO;

	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "refund_date")
	private Date refundDate;

	/**
	 * 訂單類型 1:一般 2:SCM 3:淘寶商城/京東商城
	 */
	@Column(name = "order_type", length = 1)
	private String orderType;

	/**
	 * 轉單SupplierId
	 */
	@Column(name = "scm_supplier_id", length = 6)
	private String scmSupplierId;

	/**
	 * 到店時間
	 */
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "LOGISTIC_FINAL_DT")
	private Date logisticFinalDt;

	/**
	 * 簽收時間
	 */
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "LOGISTIC_SIGN_DT")
	private Date logisticSignDt;

	/**
	 * 店點代碼
	 */
	@Column(name = "STORE_ID", length = 10)
	private String storeId = " ";

	/** COD手續費 */
	@Column(name = "COD_FEE", columnDefinition = "numeric(10,2)")
	private BigDecimal codFee = BigDecimal.ZERO;
	/** 已退COD手續費 */
	@Column(name = "RETURNED_COD_FEE", columnDefinition = "numeric(10,2)")
	private BigDecimal returnedCodFee = BigDecimal.ZERO;
	/** 物流配送差異化地址版本 **/
	@Column(name = "VERSION", length = 14)
	private String version;

	/** joinMustPay, 合併結帳的總金額, 预设 mustPay */
	@Column(name = "JOIN_MUST_PAY", columnDefinition = "numeric(10,2)")
	private BigDecimal joinMustPay;
	/** joinOrder, 合併結帳的訂單編號, 以 , 串接(包含自己訂單編號), 预设 orderId */
	@Column(name = "JOIN_ORDERS", length = 500)
	private String joinOrders;
	/** paymentTxnId, 付款的代表訂單編號, joinOrders 第一筆訂單編號, 後台需求 */
	@Transient
	private String paymentTxnId;

	/** logisticProviderTp, 限物流商代码：50(不限物流)、51(限物流、可cod)、52(限物流、不可cod),后台需求 */
	@Column(name = "LOGISTIC_PROVIDER_TP", length = 2)
	private String logisticProviderTp = ORDER_LOGISTIC_PROVIDER_TP.DEFAULT_PROVIDER.getValue();
	@Column(name = "INSTALLMENT_FEE", columnDefinition = "numeric(10,2)")
	private BigDecimal installmentFee = BigDecimal.ZERO;
	@Column(name = "RETURN_INSTALLMENT_FEE", columnDefinition = "numeric(10,2)")
	private BigDecimal returnInstallmentFee = BigDecimal.ZERO;

	/**
	 * 订单使用分期付款的资料
	 */
	@OneToOne
	@PrimaryKeyJoinColumn
	@LazyCollection(LazyCollectionOption.TRUE)
	private OrderCreditCardCampaign orderCreditCardCampaign;

	/** 是否自行配送 **/
	@Column(name = "IS_SELF_SHIP", length = 1)
	private String isSelfShip = "N";

	// /**
	// * 集购活动资料
	// */
	// @OneToOne
	// @JoinColumn(name = "tuangouId", referencedColumnName = "TUANGOU_ID")
	// @LazyCollection(LazyCollectionOption.TRUE)
	// @NotFound(action = NotFoundAction.IGNORE)
	// private ShelfTuangou shelfTuangou;

	/**
	 * 集购活动编号
	 */
	@Column(name = "TUANGOU_ID")
	private Long tuangouId;

	/**
	 * 集购活动名称
	 */
	@Column(name = "TUANGOU_NAME", length = 300)
	private String tuangouName;

	/**
	 * 集购是否已同步
	 */
	@Column(name = "IS_TUANGOU_SYNC")
	private boolean isTuangouSync = false;

	/**
	 * 允许拆单 Y/N
	 */
	@Column(name = "allow_split", length = 1)
	private String allowSplit = "N";

	/**
	 * 拆单类型 1:部分取消拆單 2:分批出貨拆單
	 */
	@Column(name = "split_type", length = 1)
	private String splitType = " ";

	/**
	 * 礼品卡余额
	 */
	@Column(name = "GIFTCARD_BALANCE", columnDefinition = "numeric(10,2)")
	private BigDecimal giftcardBalance = BigDecimal.ZERO;

	/**
	 * 退回礼品卡余额
	 */
	@Column(name = "RETURN_GIFTCARD_BALANCE", columnDefinition = "numeric(10,2)")
	private BigDecimal returnGiftcardBalance = BigDecimal.ZERO;

	/**
	 * 礼品卡支付运费
	 */
	@Column(name = "GIFTCARD_BALANCE_SHIPFARE", columnDefinition = "numeric(10,2)")
	private BigDecimal giftcardBalanceShipfare = BigDecimal.ZERO;

	/**
	 * 淘宝/京东商城订单编号
	 */
	@Column(name = "OUTER_ORDER_ID", length = 30)
	private String outerOrderId;
	@Column(name = "POINT_AMOUNT", columnDefinition = "numeric(10,2)")
	private BigDecimal pointAmount = BigDecimal.ZERO;

	/**
	 * 订单使用会员积分的资料
	 */
	@XmlTransient
	@OneToOne(fetch = FetchType.LAZY, optional = true)
	@PrimaryKeyJoinColumn
	@NotFound(action = NotFoundAction.IGNORE)
	private OrderBonusCampaign orderBonusCampaign;

	/**
	 * 积分发送日期
	 */
	@XmlTransient
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "BONUS_SENDDATE")
	private Date bonusSendDate;

	/**
	 * 異常訂單註記
	 */
	@Column(name = "EXCEPTION_FLAG", length = 1)
	private String exceptionFlag = "N";

	/**
	 * 账户余额卡支付运费
	 */
	@Column(name = "MY_WALLET_SHIPFARE", columnDefinition = "numeric(10,2)")
	private BigDecimal myWalletShipfare = BigDecimal.ZERO;

	/**
	 * 訂單資料轉換註記
	 */
	@XmlTransient
	@Column(name = "TRANSLATE_FLAG", length = 1)
	private String translateFlag;

	/**
	 * @return the pointAmount
	 */
	public BigDecimal getPointAmount() {
		return pointAmount;
	}

	/**
	 * @param pointAmount the pointAmount to set
	 */
	public void setPointAmount(BigDecimal pointAmount) {
		this.pointAmount = pointAmount;
	}

	/**
	 * @return the installmentFee
	 */
	public BigDecimal getInstallmentFee() {
		return installmentFee;
	}

	/**
	 * @param installmentFee the installmentFee to set
	 */
	public void setInstallmentFee(BigDecimal installmentFee) {
		this.installmentFee = installmentFee;
	}

	/**
	 * @return the returnInstallmentFee
	 */
	public BigDecimal getReturnInstallmentFee() {
		return returnInstallmentFee;
	}

	/**
	 * @param returnInstallmentFee the returnInstallmentFee to set
	 */
	public void setReturnInstallmentFee(BigDecimal returnInstallmentFee) {
		this.returnInstallmentFee = returnInstallmentFee;
	}

	/**
	 * @return the orgOrderId
	 */
	public String getOrgOrderId() {
		return orgOrderId;
	}

	/**
	 * @param orgOrderId the orgOrderId to set
	 */
	public void setOrgOrderId(String orgOrderId) {
		this.orgOrderId = orgOrderId;
	}

	/**
	 * @return the returnedCodFee
	 */
	public BigDecimal getReturnedCodFee() {
		return returnedCodFee;
	}

	/**
	 * @param returnedCodFee the returnedCodFee to set
	 */
	public void setReturnedCodFee(BigDecimal returnedCodFee) {
		this.returnedCodFee = returnedCodFee;
	}

	/** default constructor */
	public Orders() {
		super();
	}

	/** default constructor */
	public Orders(CartOrders cart) {
		super();
		this.memberId = cart.getMemberId();
		this.loginId = cart.getLoginId();
		this.memberName = cart.getMemberName();
		this.memo = cart.getMemo();
		this.channel = StringUtils.defaultIfEmpty(cart.getChannel(), "yaodian100");
		this.channelSeq = cart.getChannelSeq();

		this.orderDt = DateUtil.getCurrentTime();

		this.receiverName = cart.getReceiverName();
		this.receiverProvince = cart.getReceiverProvince();
		this.receiverZip = cart.getReceiverZip();
		this.receiverAddr = cart.getReceiverAddr();
		this.receiverArea = cart.getReceiverArea();
		this.receiverCity = cart.getReceiverCity();

		this.receiverExt = StringUtils.defaultIfEmpty(cart.getReceiverExt(), " ");
		this.receiverMobile = StringUtils.defaultIfEmpty(cart.getReceiverMobile(), " ");
		this.receiverEmail = StringUtils.defaultIfEmpty(cart.getReceiverEmail(), " ");
		this.receiverPhone = StringUtils.defaultIfEmpty(cart.getReceiverPhone(), " ");
		this.receiverPhoneArea = StringUtils.defaultIfEmpty(cart.getReceiverPhoneArea(), " ");
		this.memo = cart.getMemo();
		this.allowSplit = cart.getAllowSplit();

		// this.discount = cart.getDiscount();
		// this.totalPrice = cart.getAmount().add(cart.getDiscount());
		// this.amount = this.totalPrice.subtract(this.coupon).subtract(this.discount);
		// this.totalWeight = cart.getWeightSum().multiply(BigDecimal.valueOf(1000));
		// 因为拆单, 改由建立时计算
		this.discount = BigDecimal.ZERO;
		this.totalPrice = BigDecimal.ZERO;
		this.amount = BigDecimal.ZERO;
		this.totalWeight = BigDecimal.ZERO;
	}

	public Orders addProduct(OrderProduct op) {
		getOrderProduct().add(op);
		op.setOrder(this);
		int seq = getOrderProduct().size();
		for (OrderProduct tmpOp : getOrderProduct()) {
			if (tmpOp.getProdSeq() >= seq) {
				seq = tmpOp.getProdSeq() + 1;
			}
		}
		op.setProdSeq(seq);
		return this;
	}

	public BigDecimal getAmount() {
		if (amount.compareTo(BigDecimal.ZERO) < 0) {
			amount = BigDecimal.ZERO;
		}
		return amount;
	}

	/**
	 * @return the applyCampaigns
	 */
	public List<ApplyCampaign> getApplyCampaigns() {
		if (applyCampaigns == null) {
			applyCampaigns = new ArrayList();
		}
		return applyCampaigns;
	}

	public String getB2eId() {
		return b2eId;
	}

	public BigDecimal getBenefit() {
		return benefit;
	}

	public BigDecimal getBonus() {
		return bonus;
	}

	public BigDecimal getBouns() {
		return bonus;
	}

	public BigDecimal getCampProductLimit() {
		return campProductLimit;
	}

	public BigDecimal getCash() {
		return cash;
	}

	public String getChannel() {
		return channel;
	}

	public String getChannel_child() {
		return channel_child;
	}

	public int getChannelSeq() {
		return channelSeq;
	}

	public String getClientIp() {
		return clientIp;
	}

	public BigDecimal getCoupon() {
		return coupon;
	}

	public Date getDeadline() {
		return deadline;
	}

	public BigDecimal getDiscount() {
		return discount;
	}

	public String getDomainSrc() {
		return domainSrc;
	}

	public String getFromCity() {
		return fromCity;
	}

	public String getFromDistrict() {
		return fromDistrict;
	}

	public String getFromProvince() {
		return fromProvince;
	}

	public String getInvoiceAddr() {
		return invoiceAddr;
	}

	public String getInvoiceArea() {
		return invoiceArea;
	}

	public String getInvoiceCity() {
		return invoiceCity;
	}

	public Date getInvoiceDt() {
		return invoiceDt;
	}

	public String getInvoiceNumber() {
		return invoiceNumber;
	}

	public String getInvoiceProvince() {
		return invoiceProvince;
	}

	public String getInvoiceTitle() {
		return invoiceTitle;
	}

	public String getInvoiceTp() {
		return invoiceTp;
	}

	public String getInvoiceZip() {
		return invoiceZip;
	}

	public String getLoginId() {
		return loginId;
	}

	public String getMemberId() {
		return memberId;
	}

	public String getMemberName() {
		return memberName;
	}

	public String getMemo() {
		return memo;
	}

	public BigDecimal getMustPay() {
		return mustPay;
	}

	public BigDecimal getMyWallet() {
		return myWallet;
	}

	public Date getOrderDt() {
		return orderDt;
	}

	public String getOrderId() {
		return orderId;
	}

	public List<OrderProduct> getOrderProduct() {
		if (orderProduct == null) {
			orderProduct = new ArrayList();
		}
		return orderProduct;
	}

	public String getOrderSt() {
		return orderSt;
	}

	public String getOrderType() {
		return orderType;
	}

	public Date getPaymentDt() {
		return paymentDt;
	}

	public String getPaymentId() {
		return paymentId;
	}

	public String getPaymentSrc() {
		return paymentSrc;
	}

	public String getPaymentSt() {
		return paymentSt;
	}

	public String getPaymentTp() {
		return paymentTp;
	}

	public int getProductSum() {
		for (OrderProduct product : orderProduct) {
			productSum += product.getProductCount();
		}
		return productSum;
	}

	public String getReceiverAddr() {
		return receiverAddr;
	}

	public String getReceiverArea() {
		return receiverArea;
	}

	public String getReceiverCity() {
		return receiverCity;
	}

	public String getReceiverEmail() {
		return receiverEmail;
	}

	public String getReceiverExt() {
		return receiverExt;
	}

	public String getReceiverMobile() {
		return receiverMobile;
	}

	public String getReceiverName() {
		return receiverName;
	}

	public String getReceiverPhone() {
		return receiverPhone;
	}

	public String getReceiverPhoneArea() {
		return receiverPhoneArea;
	}

	public String getReceiverProvince() {
		return receiverProvince;
	}

	public String getReceiverTp() {
		return receiverTp;
	}

	public String getReceiverZip() {
		return receiverZip;
	}

	/**
	 * @return the refundDate
	 */
	public Date getRefundDate() {
		return refundDate;
	}

	public BigDecimal getReturnBenefit() {
		return returnBenefit;
	}

	public BigDecimal getReturnBonus() {
		return returnBonus;
	}

	public BigDecimal getReturnCash() {
		return returnCash;
	}

	public BigDecimal getReturnMyWallet() {
		return returnMyWallet;
	}

	public BigDecimal getReturnShipfare() {
		return returnShipfare;
	}

	/**
	 * @return the returnTotalPrice
	 */
	public BigDecimal getReturnTotalPrice() {
		return returnTotalPrice;
	}

	public String getScmSupplierId() {
		return scmSupplierId;
	}

	public BigDecimal getShipfare() {
		return shipfare;
	}

	/**
	 * @return the syncDt
	 */
	public Date getSyncDt() {
		return syncDt;
	}

	/**
	 * @return the totalPrice
	 */
	public BigDecimal getTotalPrice() {
		return totalPrice;
	}

	public BigDecimal getTotalWeight() {
		return totalWeight;
	}

	public boolean isCampaign() {
		return isCampaign;
	}

	public boolean isSync() {
		return isSync;
	}

	/**
	 * @param amount the amount to set
	 */
	public void setAmount(BigDecimal amount) {
		// pass by XXX:因修改订单需要
		this.amount = amount;

	}

	/**
	 * @param applyCampaigns the applyCampaigns to set
	 */
	public void setApplyCampaigns(List<ApplyCampaign> applyCampaigns) {
		this.applyCampaigns = applyCampaigns;
	}

	public void setB2eId(String b2eId) {
		this.b2eId = b2eId;
	}

	public void setBenefit(BigDecimal benefit) {
		this.benefit = benefit;
	}

	public void setBonus(BigDecimal bonus) {
		this.bonus = bonus;
	}

	public void setCampaign(boolean isCampaign) {
		this.isCampaign = isCampaign;
	}

	public void setCampProductLimit(BigDecimal campProductLimit) {
		this.campProductLimit = campProductLimit;
	}

	public void setCash(BigDecimal cash) {
		this.cash = cash;
	}

	public void setChannel(String channel) {
		this.channel = channel;
	}

	public void setChannel_child(String channelChild) {
		channel_child = channelChild;
	}

	public void setChannelSeq(int channelSeq) {
		this.channelSeq = channelSeq;
	}

	public void setClientIp(String clientIp) {
		this.clientIp = clientIp;
	}

	public void setCoupon(BigDecimal coupon) {
		this.coupon = coupon;
		this.amount = this.totalPrice.subtract(this.coupon).subtract(this.discount);
	}

	public void setDeadline(Date deadline) {
		this.deadline = deadline;
	}

	public void setDiscount(BigDecimal discount) {
		this.discount = discount;
		this.amount = this.totalPrice.subtract(this.coupon).subtract(this.discount);
	}

	public void setDomainSrc(String domainSrc) {
		this.domainSrc = domainSrc;
	}

	public void setFromCity(String fromCity) {
		this.fromCity = fromCity;
	}

	public void setFromDistrict(String fromDistrict) {
		this.fromDistrict = fromDistrict;
	}

	public void setFromProvince(String fromProvince) {
		this.fromProvince = fromProvince;
	}

	public void setInvoiceAddr(String invoiceAddr) {
		this.invoiceAddr = invoiceAddr;
	}

	public void setInvoiceArea(String invoiceArea) {
		this.invoiceArea = invoiceArea;
	}

	public void setInvoiceCity(String invoiceCity) {
		this.invoiceCity = invoiceCity;
	}

	public void setInvoiceDt(Date invoiceDt) {
		this.invoiceDt = invoiceDt;
	}

	public void setInvoiceNumber(String invoiceNumber) {
		this.invoiceNumber = invoiceNumber;
	}

	public void setInvoiceProvince(String invoiceProvince) {
		this.invoiceProvince = invoiceProvince;
	}

	public void setInvoiceTitle(String invoiceTitle) {
		this.invoiceTitle = invoiceTitle;
	}

	public void setInvoiceTp(String invoiceTp) {
		this.invoiceTp = invoiceTp;
	}

	public void setInvoiceZip(String invoiceZip) {
		this.invoiceZip = invoiceZip;
	}

	public void setLoginId(String loginId) {
		this.loginId = loginId;
	}

	public void setMemberId(String memberId) {
		this.memberId = memberId;
	}

	public void setMemberName(String memberName) {
		this.memberName = memberName;
	}

	public void setMemo(String memo) {
		this.memo = memo;
	}

	public void setMustPay(BigDecimal mustPay) {
		this.mustPay = mustPay;
	}

	public void setMyWallet(BigDecimal myWallet) {
		this.myWallet = myWallet;
	}

	public void setOrderDt(Date orderDt) {
		this.orderDt = orderDt;
	}

	public void setOrderId(String orderId) {
		this.orderId = orderId;
	}

	public void setOrderProduct(List<OrderProduct> orderProduct) {
		this.orderProduct = orderProduct;
	}

	public void setOrderSt(String orderSt) {
		this.orderSt = orderSt;
	}

	public void setOrderType(String orderType) {
		this.orderType = orderType;
	}

	public void setPaymentDt(Date paymentDt) {
		this.paymentDt = paymentDt;
	}

	public void setPaymentId(String paymentId) {
		this.paymentId = paymentId;
	}

	public void setPaymentSrc(String paymentSrc) {
		this.paymentSrc = paymentSrc;
	}

	public void setPaymentSt(String paymentSt) {
		this.paymentSt = paymentSt;
	}

	public void setPaymentTp(String paymentTp) {
		this.paymentTp = paymentTp;
	}

	public void setProductSum(int productSum) {
		this.productSum = productSum;
	}

	public void setReceiverAddr(String receiverAddr) {
		this.receiverAddr = receiverAddr;
	}

	public void setReceiverArea(String receiverArea) {
		this.receiverArea = receiverArea;
	}

	public void setReceiverCity(String receiverCity) {
		this.receiverCity = receiverCity;
	}

	public void setReceiverEmail(String receiverEmail) {
		this.receiverEmail = receiverEmail;
	}

	public void setReceiverExt(String receiverExt) {
		this.receiverExt = receiverExt;
	}

	public void setReceiverMobile(String receiverMobile) {
		this.receiverMobile = receiverMobile;
	}

	public void setReceiverName(String receiverName) {
		this.receiverName = receiverName;
	}

	public void setReceiverPhone(String receiverPhone) {
		this.receiverPhone = receiverPhone;
	}

	public void setReceiverPhoneArea(String receiverPhoneArea) {
		this.receiverPhoneArea = receiverPhoneArea;
	}

	public void setReceiverProvince(String receiverProvince) {
		this.receiverProvince = receiverProvince;
	}

	public void setReceiverTp(String receiverTp) {
		this.receiverTp = receiverTp;
	}

	public void setReceiverZip(String receiverZip) {
		this.receiverZip = receiverZip;
	}

	/**
	 * @param refundDate the refundDate to set
	 */
	public void setRefundDate(Date refundDate) {
		this.refundDate = refundDate;
	}

	public void setReturnBenefit(BigDecimal returnBenefit) {
		this.returnBenefit = returnBenefit;
	}

	public void setReturnBonus(BigDecimal returnBonus) {
		this.returnBonus = returnBonus;
	}

	public void setReturnCash(BigDecimal returnCash) {
		this.returnCash = returnCash;
	}

	public void setReturnMyWallet(BigDecimal returnMyWallet) {
		this.returnMyWallet = returnMyWallet;
	}

	public void setReturnShipfare(BigDecimal returnShipfare) {
		this.returnShipfare = returnShipfare;
	}

	/**
	 * @param returnTotalPrice the returnTotalPrice to set
	 */
	public void setReturnTotalPrice(BigDecimal returnTotalPrice) {
		this.returnTotalPrice = returnTotalPrice;
	}

	public void setScmSupplierId(String scmSupplierId) {
		this.scmSupplierId = scmSupplierId;
	}

	public void setShipfare(BigDecimal shipfare) {
		this.shipfare = shipfare;
	}

	public void setSync(boolean isSync) {
		this.isSync = isSync;
	}

	/**
	 * @param syncDt the syncDt to set
	 */
	public void setSyncDt(Date syncDt) {
		this.syncDt = syncDt;
	}

	/**
	 * @param totalPrice the totalPrice to set
	 */
	public void setTotalPrice(BigDecimal totalPrice) {
		this.totalPrice = totalPrice;
		this.amount = this.totalPrice.subtract(this.coupon).subtract(this.discount);
	}

	public void setTotalWeight(BigDecimal totalWeight) {
		this.totalWeight = totalWeight;
	}

	public Date getLogisticFinalDt() {
		return logisticFinalDt;
	}

	public void setLogisticFinalDt(Date logisticFinalDt) {
		this.logisticFinalDt = logisticFinalDt;
	}

	public Date getLogisticSignDt() {
		return logisticSignDt;
	}

	public void setLogisticSignDt(Date logisticSignDt) {
		this.logisticSignDt = logisticSignDt;
	}

	public String getStoreId() {
		return storeId;
	}

	public void setStoreId(String storeId) {
		this.storeId = storeId;
	}

	public BigDecimal getCodFee() {
		return codFee;
	}

	public void setCodFee(BigDecimal codFee) {
		this.codFee = codFee;
	}

	public String getVersion() {
		return version;
	}

	public void setVersion(String version) {
		this.version = version;
	}

	public BigDecimal getReturnCoupon() {
		return returnCoupon;
	}

	public void setReturnCoupon(BigDecimal returnCoupon) {
		this.returnCoupon = returnCoupon;
	}

	/**
	 * @return the joinMustPay
	 */
	public BigDecimal getJoinMustPay() {
		return joinMustPay;
	}

	/**
	 * @param joinMustPay the joinMustPay to set
	 */
	public void setJoinMustPay(BigDecimal joinMustPay) {
		this.joinMustPay = joinMustPay;
	}

	/**
	 * @return the joinOrders
	 */
	public String getJoinOrders() {
		return joinOrders;
	}

	/**
	 * @param joinOrder the joinOrder to set
	 */
	public void setJoinOrders(String joinOrders) {
		this.joinOrders = joinOrders;
	}

	/**
	 * @return the paymentTxnId
	 */
	public String getPaymentTxnId() {
		if (paymentTxnId == null && ("50".equals(paymentTp) || "70".equals(paymentTp) || "80".equals(paymentTp))
				&& joinOrders != null) {
			paymentTxnId = StringUtils.split(joinOrders, ",")[0];
		}
		return paymentTxnId;
	}

	/**
	 * @param paymentTxnId the paymentTxnId to set
	 */
	public void setPaymentTxnId(String paymentTxnId) {
		this.paymentTxnId = paymentTxnId;
	}

	/**
	 * @param logisticProviderTp the logisticProviderTp to set
	 */
	public void setLogisticProviderTp(String logisticProviderTp) {
		this.logisticProviderTp = logisticProviderTp;
	}

	/**
	 * @return the logisticProviderTp
	 */
	public String getLogisticProviderTp() {
		return logisticProviderTp;
	}

	public OrderCreditCardCampaign getOrderCreditCardCampaign() {
		// if (null == orderCreditCardCampaign) {
		// orderCreditCardCampaign = new OrderCreditCardCampaign();
		// }
		return orderCreditCardCampaign;
	}

	public void setOrderCreditCardCampaign(OrderCreditCardCampaign orderCreditCardCampaign) {
		this.orderCreditCardCampaign = orderCreditCardCampaign;
	}

	public String getIsSelfShip() {
		// 相容於舊訂單資料，回傳預設值
		if (null == isSelfShip || StringUtils.isBlank(isSelfShip)) {
			return "N";
		} else {
			return isSelfShip;
		}
	}

	public void setIsSelfShip(String isSelfShip) {
		this.isSelfShip = isSelfShip;
	}

	// public ShelfTuangou getShelfTuangou() {
	// return shelfTuangou;
	// }

	public Long getTuangouId() {
		return tuangouId;
	}

	public boolean isTuangouSync() {
		return isTuangouSync;
	}

	// public void setShelfTuangou(ShelfTuangou shelfTuangou) {
	// this.shelfTuangou = shelfTuangou;
	// }

	public void setTuangouId(Long tuangouId) {
		this.tuangouId = tuangouId;
	}

	public void setTuangouSync(boolean isTuangouSync) {
		this.isTuangouSync = isTuangouSync;
	}

	public String getTuangouName() {
		return tuangouName;
	}

	public void setTuangouName(String tuangouName) {
		this.tuangouName = tuangouName;
	}

	public String getAllowSplit() {
		return allowSplit;
	}

	public void setAllowSplit(String allowSplit) {
		this.allowSplit = allowSplit;
	}

	public String getSplitType() {
		return splitType;
	}

	public void setSplitType(String splitType) {
		this.splitType = splitType;
	}

	public String getNewOrderId() {
		return newOrderId;
	}

	public void setNewOrderId(String newOrderId) {
		this.newOrderId = newOrderId;
	}

	public BigDecimal getGiftcardBalance() {
		return giftcardBalance;
	}

	public BigDecimal getReturnGiftcardBalance() {
		return returnGiftcardBalance;
	}

	public BigDecimal getGiftcardBalanceShipfare() {
		return giftcardBalanceShipfare;
	}

	public void setGiftcardBalance(BigDecimal giftcardBalance) {
		this.giftcardBalance = giftcardBalance;
	}

	public void setReturnGiftcardBalance(BigDecimal returnGiftcardBalance) {
		this.returnGiftcardBalance = returnGiftcardBalance;
	}

	public void setGiftcardBalanceShipfare(BigDecimal giftcardBalanceShipfare) {
		this.giftcardBalanceShipfare = giftcardBalanceShipfare;
	}

	public String getOuterOrderId() {
		return outerOrderId;
	}

	public void setOuterOrderId(String outerOrderId) {
		this.outerOrderId = outerOrderId;
	}

	public OrderBonusCampaign getOrderBonusCampaign() {
		return orderBonusCampaign;
	}

	public void setOrderBonusCampaign(OrderBonusCampaign orderBonusCampaign) {
		this.orderBonusCampaign = orderBonusCampaign;
	}

	public Date getBonusSendDate() {
		return bonusSendDate;
	}

	public void setBonusSendDate(Date bonusSendDate) {
		this.bonusSendDate = bonusSendDate;
	}

	public String getExceptionFlag() {
		return exceptionFlag;
	}

	public void setExceptionFlag(String exceptionFlag) {
		this.exceptionFlag = exceptionFlag;
	}

	public BigDecimal getMyWalletShipfare() {
		return myWalletShipfare;
	}

	public void setMyWalletShipfare(BigDecimal myWalletShipfare) {
		this.myWalletShipfare = myWalletShipfare;
	}

	public String getTranslateFlag() {
		return translateFlag;
	}

	public void setTranslateFlag(String translateFlag) {
		this.translateFlag = translateFlag;
	}
}